package club.hicode.daydayup.redis.lettuce.queue;

import io.lettuce.core.KeyValue;
import io.lettuce.core.RedisClient;
import io.lettuce.core.api.StatefulRedisConnection;
import io.lettuce.core.api.sync.RedisCommands;

/**
 * List设置的Queue
 * @author Liu Chunfu
 * @date 2018-08-27 下午3:45
 **/
public class RedisQueue {


	private RedisCommands commands;

	public RedisQueue() {
		RedisClient redisClient = RedisClient.create("redis://@localhost:6379/0");
		StatefulRedisConnection<String, String> connection = redisClient.connect();
		this.commands = connection.sync();
	}

	private static final String NORMAL = "normal-queue";

	public void provider(String value) {
		commands.lpush(NORMAL, value);
	}


	public KeyValue get(Long seconds) {

		KeyValue brpop = commands.brpop(seconds, NORMAL);
		return brpop;
	}
}
